//
//  PersonVC.m
//  SelfDrivingTravelling-IOS
//
//  Created by Teplot_01 on 16/7/21.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "PersonVC.h"
#import "PersonCell.h"
#import "MyTravelsVC.h"
#import "CreateActivityVC.h"
#import "OutMoneyVC.h"
#import "SettingVC.h"
#import "ClubPerson.h"
#import "MyJoinClub.h"
#import "MyActityVC.h"
#import "SystemNewsVC.h"
#import "MyBillVC.h"
#import "LeaderSettingVC.h"
#import "TouristPersonalInfoVC.h"
@interface PersonVC ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation PersonVC
{
    UITableView *_personTableView;
    UIImageView *_imageView;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [_personTableView reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initPersonTableView];
    //去除多余的分割线
    _personTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
- (void)initPersonTableView{
    _personTableView = [[UITableView alloc]initWithFrame:self.view.frame];
    _personTableView.backgroundColor = LighterGrayColor;
    _personTableView.dataSource = self;
    _personTableView.delegate = self;
    [self.view addSubview:_personTableView];
}

#pragma - mark UITabelViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 2;
    }
    if (section == 1) {
        return 4;
    }else{
        return 1;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]init];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 70, 70)];
            _imageView.layer.masksToBounds = YES;
            _imageView.layer.cornerRadius = 8;
            _imageView.contentMode = UIViewContentModeScaleAspectFill;
            NSString *urlStr = [NSString readToNSDefaultsWithKey:kPhotoUrl];
            [_imageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"userIcon"]];
            [cell.contentView addSubview:_imageView];
            UILabel *nameLb = [[UILabel alloc]initWithFrame:CGRectMake(90, 20, 150, 20)];
            NSString *nickStr = [NSString readToNSDefaultsWithKey:kNickName];
            if ([nickStr isEqualToString:@""]) {
                nameLb.text = @"请更改昵称";
            }else{
                nameLb.text = nickStr;
            }
            
            nameLb.textColor = Theme_Color;
            [cell.contentView addSubview:nameLb];
            UILabel *accountLb = [[UILabel alloc]initWithFrame:CGRectMake(90, 55, 200, 20)];
            accountLb.text = [@"账户名：" stringByAppendingString:[NSString readToNSDefaultsWithKey:kPhone]];
            accountLb.font = [UIFont systemFontOfSize:15];
            [cell.contentView addSubview:accountLb];
            return cell;
        }
        if (indexPath.row == 1) {
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.backgroundColor = superBackgroundColor;
            UILabel *clubWallet = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 100, 25)];
            clubWallet.text = @"我的钱包";
            clubWallet.font = [UIFont systemFontOfSize:15];
            [cell.contentView addSubview:clubWallet];
            UILabel *walletLb = [[UILabel alloc]initWithFrame:CGRectMake(10, 30, 100, 25)];
            walletLb.text = @"¥333.00元";
            walletLb.font = [UIFont systemFontOfSize:13];
            [cell.contentView addSubview:walletLb];
            UIButton *intoBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth - 130, 25, 50, 25)];
            intoBtn.backgroundColor = White_Color;
            intoBtn.layer.borderWidth = 1;
            intoBtn.layer.borderColor = Gray_Color.CGColor;
            intoBtn.layer.cornerRadius = 3;
            [intoBtn setTitle:@"充值" forState:UIControlStateNormal];
            [intoBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
            [intoBtn setTitleColor:Gray_Color forState:UIControlStateNormal];
            [cell.contentView addSubview:intoBtn];
            UIButton *outBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth - 70, 25, 50, 25)];
            outBtn.backgroundColor = White_Color;
            outBtn.layer.borderWidth = 1;
            outBtn.layer.borderColor = Gray_Color.CGColor;
            outBtn.layer.cornerRadius = 3;
            [outBtn setTitle:@"提现" forState:UIControlStateNormal];
            [outBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
            [outBtn setTitleColor:Gray_Color forState:UIControlStateNormal];
            [cell.contentView addSubview:outBtn];
            return cell;
        }

        return cell;
    }else{

        NSArray *titleArr = [[NSArray alloc] initWithObjects:@"我的账单",@"我的俱乐部",@"我的游记",@"我的活动",@"设置",nil];
        NSArray *iconArr = [[NSArray alloc] initWithObjects:@"wodezhangdan",@"huiyuanguanli",@"wodeyouji",@"wodehuodong",@"setting",nil];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        if (indexPath.section == 1) {
            cell.textLabel.text = [titleArr objectAtIndex:indexPath.row];
            cell.imageView.image = [UIImage imageNamed:[iconArr objectAtIndex:indexPath.row]];
        }else{
            cell.textLabel.text = [titleArr objectAtIndex:indexPath.row+4];
            cell.imageView.image = [UIImage imageNamed:[iconArr objectAtIndex:indexPath.row+4]];
        }
        
        return cell;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSInteger index = [tableView indexWithIndexPath:indexPath];
    switch (index) {
        case 0:
        {
            TouristPersonalInfoVC *vc = [[TouristPersonalInfoVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            MyBillVC *vc = [[MyBillVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            break;
        case 3:
        {
            MyJoinClub *vc = [[MyJoinClub alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4:
        {
            MyTravelsVC *vc = [[MyTravelsVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 5:
        {
            MyActityVC *vc = [[MyActityVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
//        case 6:
//        {
//            SystemNewsVC *vc = [[SystemNewsVC alloc]init];
//            vc.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:vc animated:YES];
//        }
//            break;
        case 6:
        {
            //游客和领队的个人中心界面相同
            LeaderSettingVC *vc = [[LeaderSettingVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        return 90;
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        return 56;
    }else{
        return 40;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0 || section == 1) {
        return 0;
    }
    return 15;
}
//Btn的点击事件
- (void)meneyBtnAction{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"专项资金" message:@"专项资金是指：仅可用于参加制定俱乐部发起的活动的资金" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"我明白了" style:UIAlertActionStyleCancel handler:nil];
    [alertController addAction:cancelAction];
    [self presentViewController:alertController animated:YES completion:nil];
}
- (void)intoMoneyAction{
    OutMoneyVC *vc = [[OutMoneyVC alloc]init];
    vc.isIntoMoney = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)outMoneyAction{
    OutMoneyVC *vc = [[OutMoneyVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
